In [1]:
cd C:\Users\alpha\Documents\work\burned pixels\ecoregions_countries_climates_continents
C:\Users\alpha\Documents\work\burned pixels\ecoregions_countries_climates_continents
In [3]:
import geopandas as gpd
import matplotlib.pyplot as plt
import pickle
import pandas as pd
import numpy as np
import calendar
In [2]:
import matplotlib.cm as cm
import matplotlib.colors as cls
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
In [3]:
#latex
import matplotlib
matplotlib.rcParams['mathtext.fontset'] = 'custom'
matplotlib.rcParams['mathtext.rm'] = 'Times New Roman'
matplotlib.rcParams['mathtext.it'] = 'Times New Roman:italic'
matplotlib.rcParams['mathtext.bf'] = 'Times New Roman:bold'
In [4]:
from scipy.stats import boxcox, probplot
In [4]:
bios = gpd.read_file('biomes_hemispheres')
In [5]:
bios.columns
Out[5]:
Index(['OBJECTID', 'BIOME_NUM', 'is_north', 'SUM_2001_J', 'SUM_2001_F',
       'SUM_2001_M', 'SUM_2001_A', 'SUM_2001_1', 'SUM_2001_2', 'SUM_2001_3',
       ...
       'SUM_2017_3', 'SUM_2017_4', 'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N',
       'SUM_2017_D', 'SUM_Area', 'Shape_Leng', 'Shape_Area', 'geometry'],
      dtype='object', length=211)
In [7]:
area = bios['SUM_Area']*1e-6
In [10]:
data_columns = bios.columns[3:3+17*12]
In [11]:
inter_cols = {}
for yr in range(17):
    inter_cols[yr] = data_columns[12*yr:12*yr +12]
In [12]:
intra_cols = {}
for mo in range(12):
    intra_cols[mo] = [data_columns[mo + yr *12  ] for yr in range(17)]

for yr in range(17):
    inter = bios[  inter_cols[yr]].sum(axis=1)/area
    label = 'inter_' + str(yr +2001)
    bios= bios.assign(label=inter)
    bios = bios.rename(columns={'label': label})

inter_columns = bios.columns[-17:]

inter_max = bios[inter_columns].max().max()

for mo in range(12):
    intra = bios[ intra_cols[mo]].sum(axis=1)/(17*area)
    label = 'intra_{:02}'.format(mo)
    bios = bios.assign(label=intra)
    bios = bios.rename(columns={'label': label})

intra_columns = bios.columns[-12:]
In [18]:
intra_max = bios[intra_columns].max().max()
In [76]:
def draw_map(df,column,title=None,vmin=0,vmax=1,name='name',dpi=100,cmap='OrRd'):
    fig, ax = plt.subplots(figsize=(12, 8))

    ax.set_aspect('equal')
    ax = df.plot(ax =ax, column=column, cmap=cmap,vmin=vmin, vmax=vmax)
    ax.set_axis_off()
    
    norm = cls.Normalize(vmin, vmax)
    cmmapable = cm.ScalarMappable(norm, cmap)
    
    cmmapable._A = []
    cbaxes = inset_axes(ax, width="80%", height="1%", loc=8)
    cb = plt.colorbar(cmmapable, cax=cbaxes,orientation="horizontal") 

    cb.set_label(title, fontsize=20, family='Times New Roman')
    cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=15, family='Times New Roman')

    plt.show()
    fig.savefig(name, dpi=dpi, bbox_inches='tight')
In [ ]:
''' backup
def draw_map(df,column,title=None,vmin=0,vmax=1,name='name',dpi=100):
    fig, ax = plt.subplots(figsize=(12, 8))

    ax.set_aspect('equal')
    ax = df.plot(ax =ax, column=column, cmap='OrRd',vmin=vmin, vmax=vmax)
    ax.set_axis_off()
    
    norm = cls.Normalize(vmin, vmax)
    cmmapable = cm.ScalarMappable(norm, 'OrRd')
    
    cmmapable._A = []
    cbaxes = inset_axes(ax, width="80%", height="1%", loc=3)
    cb = plt.colorbar(cmmapable, cax=cbaxes,orientation="horizontal") 

    cb.set_label(title, fontsize=20, family='Times New Roman')
    cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=15, family='Times New Roman')

    plt.show()
    fig.savefig(name, dpi=dpi, bbox_inches='tight')
'''

Inter-anual

In [78]:
lambdas = []
for yr in range(17):
    column= 'inter_{}'.format(2001 + yr)
    test_column, lbd = boxcox(bios[column] + 1e-25)
    lambdas.append(lbd)
lmbda=  sum(lambdas)/len(lambdas)
In [79]:
lambdas
Out[79]:
[0.11549818404472534,
 0.13247022652837614,
 0.14040360802627982,
 0.1317583680617727,
 0.13043098141653348,
 0.13325660542853673,
 0.12843417474371077,
 0.12925781778553824,
 0.1306853957846011,
 0.11861652800316695,
 0.12884257581501873,
 0.13166418002449554,
 0.13013977100347757,
 0.11986988692310972,
 0.12033228362428698,
 0.1314218302256409,
 0.1224914409660524]
In [22]:
probplot(bios.inter_2017, plot=plt.gca());
In [23]:
probplot(test_column, plot=plt.gca());
In [80]:
maxs = []
mins = []
for yr in range(17):
    column= 'inter_{}'.format(2001 + yr)
    test_column = boxcox(bios[column] + 1e-25,lmbda=lmbda)
    maxs.append(test_column.max())
    mins.append(test_column.min())

box_min = min(mins)
box_delta =max(maxs) - box_min
In [81]:
for yr in range(17):
    column = 'inter_{}'.format(yr +2001)
    test_column = (boxcox(bios[column] + 1e-25,lmbda=lmbda) - box_min)/box_delta
    bios = bios.assign(test_column =test_column)
    yr_name = str(yr +2001)
   
    title = r'Burned area index (#/$\mathrm{km}^{2}$) by biome in each hemisphere ' +yr_name
   
    name = 'inter_biomes_nsparts_index_{}'.format(yr +2001)
    draw_map(bios,'test_column',title=title,name=name)

Intra-anual

In [82]:
lambdas = []
for mo in range(12):
    column= 'intra_{:02}'.format(mo)
    test_column, lbd = boxcox(bios[column] + 1e-25)
    lambdas.append(lbd)
lmbda=  sum(lambdas)/len(lambdas)
In [84]:
lambdas
Out[84]:
[0.09657411870392897,
 0.09397366386268413,
 0.12691276070279361,
 0.11853975794400545,
 0.13844976415288773,
 0.1244002609968398,
 0.11776589776775662,
 0.11683053353063909,
 0.11450503528246088,
 0.10609081953392038,
 0.10146759197041494,
 0.09515963130263318]
In [83]:
probplot(bios.intra_11, plot=plt.gca());
In [29]:
probplot(test_column, plot=plt.gca());
In [85]:
maxs = []
mins = []
for mo in range(12):
    column= column= 'intra_{:02}'.format(mo)
    test_column = boxcox(bios[column] + 1e-25,lmbda=lmbda)
    maxs.append(test_column.max())
    mins.append(test_column.min())

box_min = min(mins)
box_delta =max(maxs) - box_min
In [86]:
for mo in range(12):
    column = 'intra_{:02}'.format(mo)
    test_column = (boxcox(bios[column] + 1e-25,lmbda=lmbda) - box_min)/box_delta
    bios= bios.assign(test_column =test_column)
    mo_name = calendar.month_name[mo + 1]
   
    title = r'Burned area index (#/$\mathrm{km}^{2}$) by biome in each hemisphere ' +mo_name + ' (2001-2017)'
    
    name = 'intra_biomes_nsparts_index_{:02}'.format(mo)
    draw_map(bios,'test_column',title=title,name=name)

Total

In [32]:
total = bios[data_columns].sum(axis=1)/17

total = total/area

bios= bios.assign(total=total)
In [77]:
column = 'total'
test_column, lbd = boxcox(bios[column] + 1e-25)
test_column = (test_column - test_column.min())/(test_column.max() - test_column.min())
bios = bios.assign(test_column =test_column)
title = r'Burned area index (#/$\mathrm{km}^{2}$) by biome in each hemisphere (2001-2017)' 

name = 'total_biomes_nsparts_index'
draw_map(bios,'test_column',title=title,name=name,dpi=600)

Anomalias

Inter-anual

In [38]:
inter_medias = bios[inter_columns].mean(axis=1)
In [41]:
matriz = np.array([[4,6,8],[6,8,10]])
In [43]:
matriz - np.array([[0],[2]])
Out[43]:
array([[4, 6, 8],
       [4, 6, 8]])
In [53]:
matriz.shape
Out[53]:
(2, 3)
In [54]:
np.array([[0],[2]]).shape
Out[54]:
(2, 1)
In [58]:
anomalias = np.array(bios[inter_columns]) -  inter_medias.values.reshape(27,1)
In [45]:
bios[inter_columns]
Out[45]:
inter_2001 inter_2002 inter_2003 inter_2004 inter_2005 inter_2006 inter_2007 inter_2008 inter_2009 inter_2010 inter_2011 inter_2012 inter_2013 inter_2014 inter_2015 inter_2016 inter_2017
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000
1 0.000000 0.000005 0.000010 0.000003 0.000004 0.000016 0.000003 0.000003 0.000031 0.000000 0.000003 0.000007 5.462977e-07 0.000000 0.000000 0.000001 0.000000
2 0.047521 0.076068 0.076465 0.079402 0.093502 0.071258 0.096334 0.061346 0.064016 0.093142 0.058514 0.064990 5.138119e-02 0.058642 0.074753 0.058978 0.060809
3 0.034023 0.039508 0.073047 0.083512 0.072145 0.058385 0.087838 0.056454 0.074407 0.082565 0.052387 0.067192 6.126097e-02 0.062217 0.070823 0.070867 0.055229
4 0.072870 0.087703 0.084904 0.122496 0.116345 0.082425 0.149634 0.081923 0.060723 0.150865 0.069885 0.100991 6.301827e-02 0.061261 0.105633 0.098319 0.076096
5 0.086836 0.094555 0.125449 0.154393 0.106404 0.105181 0.119554 0.112571 0.116948 0.098936 0.123857 0.118240 1.001687e-01 0.093120 0.113729 0.091015 0.121322
6 0.035056 0.042468 0.069894 0.027477 0.089520 0.050962 0.043930 0.061433 0.054920 0.030546 0.131657 0.068319 5.678596e-02 0.026642 0.020432 0.048741 0.069855
7 0.029098 0.048656 0.054778 0.024103 0.016866 0.064001 0.017241 0.008843 0.031539 0.006307 0.041213 0.026789 3.237772e-02 0.024398 0.018662 0.024845 0.033752
8 0.021624 0.028188 0.026721 0.027089 0.031283 0.038570 0.030720 0.050702 0.041731 0.035059 0.029887 0.033241 2.128196e-02 0.035199 0.025436 0.017554 0.021997
9 0.005998 0.026541 0.025904 0.005555 0.008045 0.012225 0.018509 0.027902 0.009625 0.009517 0.016561 0.026370 1.761131e-02 0.015946 0.020750 0.010911 0.027393
10 0.010041 0.024139 0.037167 0.014423 0.014518 0.015511 0.009663 0.019393 0.011776 0.013669 0.018976 0.029045 2.327012e-02 0.027830 0.021612 0.016264 0.015823
11 0.748677 0.696804 0.721054 0.822319 0.739055 0.723421 0.796940 0.707566 0.695598 0.754241 0.782219 0.828883 6.526381e-01 0.683454 0.684785 0.626272 0.668016
12 0.584928 0.592581 0.670168 0.620278 0.735867 0.589431 0.649654 0.613481 0.514674 0.528638 0.553869 0.509473 5.194914e-01 0.485283 0.468422 0.585141 0.473098
13 0.106718 0.046370 0.049552 0.019848 0.021067 0.015770 0.006652 0.015294 0.016340 0.006377 0.020399 0.016747 1.491790e-02 0.023587 0.016976 0.036117 0.050066
14 0.072921 0.116338 0.084369 0.074839 0.091262 0.097523 0.082140 0.112901 0.052278 0.076596 0.054199 0.060166 2.074878e-02 0.078761 0.074685 0.040418 0.073410
15 0.771776 0.964372 0.686142 0.812639 0.937373 0.757694 0.824067 0.797177 0.719120 0.847723 0.660443 0.784084 6.730329e-01 0.589442 0.725515 0.721452 0.643498
16 0.541217 1.063833 0.618616 0.795856 0.700235 0.703267 0.784351 0.793291 0.962006 0.442947 0.828018 0.729685 6.371421e-01 0.677844 0.946413 0.694031 0.635496
17 0.079299 0.090975 0.112876 0.069274 0.092837 0.080094 0.076181 0.078217 0.068832 0.090931 0.083040 0.069390 6.981568e-02 0.070018 0.063516 0.048201 0.066648
18 0.002930 0.006434 0.005321 0.003741 0.003398 0.004782 0.004421 0.003632 0.003080 0.003485 0.003976 0.003964 2.306099e-03 0.002411 0.003797 0.002171 0.002025
19 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000
20 0.001741 0.002741 0.009585 0.010173 0.003218 0.001153 0.002208 0.001646 0.001829 0.006873 0.001070 0.001654 1.318784e-03 0.000751 0.003388 0.004603 0.002067
21 0.041173 0.068758 0.043392 0.061789 0.058256 0.045308 0.024458 0.026639 0.046589 0.052355 0.026336 0.036716 1.943181e-02 0.051047 0.055112 0.036625 0.073661
22 0.019080 0.016105 0.034172 0.019516 0.019392 0.013835 0.034651 0.016257 0.024260 0.015301 0.014927 0.024276 1.792923e-02 0.014123 0.022806 0.021058 0.033771
23 0.372587 0.408419 0.045588 0.130526 0.044709 0.187594 0.159600 0.107300 0.042331 0.108560 0.506366 0.363277 7.190637e-02 0.119366 0.125376 0.033206 0.219797
24 0.009365 0.029262 0.015035 0.023997 0.025421 0.025155 0.017233 0.013051 0.013034 0.018543 0.014165 0.012830 9.764005e-03 0.013567 0.015172 0.011916 0.027799
25 0.010647 0.066837 0.040874 0.059064 0.042183 0.093326 0.029282 0.024870 0.046865 0.028810 0.043235 0.040294 4.656843e-02 0.054597 0.088643 0.039079 0.027083
26 0.031949 0.038983 0.086925 0.077045 0.070396 0.077495 0.069128 0.054948 0.076532 0.061753 0.064178 0.055275 6.154448e-02 0.075962 0.086954 0.070002 0.051241
In [61]:
anomalias[0,:]
Out[61]:
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
In [56]:
 inter_medias.values.reshape(27,1)
Out[56]:
array([[0.00000000e+00],
       [5.14162559e-06],
       [6.98307459e-02],
       [6.48152618e-02],
       [9.32406375e-02],
       [1.10722165e-01],
       [5.46259154e-02],
       [2.96158009e-02],
       [3.03695063e-02],
       [1.67860444e-02],
       [1.90069836e-02],
       [7.25408440e-01],
       [5.70263335e-01],
       [2.83998683e-02],
       [7.43267022e-02],
       [7.59738282e-01],
       [7.38485237e-01],
       [7.70673324e-02],
       [3.63958779e-03],
       [0.00000000e+00],
       [3.29509800e-03],
       [4.51556728e-02],
       [2.12623553e-02],
       [1.79206473e-01],
       [1.73711282e-02],
       [4.60151734e-02],
       [6.53124234e-02]])
In [64]:
anomalias.max()
Out[64]:
0.32715982717537395
In [65]:
for yr in range(17):
    test_column = anomalias[:,yr]
    bios = bios.assign(test_column =test_column)
    yr_name = str(yr +2001)
    #"Burnt area pixels (#/km2) by biome in 2001
    title = r'Anomalies burned pixels (#/$\mathrm{km}^{2}$) by biome N-S parts in ' +yr_name
    #title = r'Burned Area Pixels/$\mathrm{Km}^{2}$ by Climate 2001-2017 {} '.format(calendar.month_name[mo + 1])
    #title =(r'ABC123 vs $\mathrm{ABC123}^{123}$')
    name = 'inter_anomalies_biomes_nsparts_index_{}'.format(yr +2001)
    draw_map(bios,'test_column',title=title,name=name,cmap='seismic',vmin=anomalias.min(),vmax=anomalias.max())

Intra-anual

In [87]:
intra_medias = bios[intra_columns].mean(axis=1)
In [88]:
anomalias = np.array(bios[intra_columns]) -  intra_medias.values.reshape(27,1)
In [89]:
bigger = abs(anomalias.max()) if abs(anomalias.max()) >= abs(anomalias.min()) else abs(anomalias.min())

vmax = bigger; vmin = -1 * bigger
In [91]:
for mo in range(12):
    test_column = anomalias[:,mo]
    bios= bios.assign(test_column =test_column)
    mo_name = calendar.month_name[mo + 1]
   
    #title = r'Anomalies burned area pixels (#/$\mathrm{km}^{2}$) by biome in each hemisphere ' +mo_name + ' (2001-2017)'
    title = r'Anomalies (#/$\mathrm{km}^{2}$) by biome ' +mo_name + ' (2001-2017)'
    
    name = 'intra_anomalies_biomes_nsparts_index_{:02}'.format(mo)
    draw_map(bios,'test_column',title=title,name=name,cmap='seismic',vmin=vmin,vmax=vmax,dpi=600)
In [93]:
anomalias.shape
Out[93]:
(27, 12)

Total

In [73]:
anomalia = bios.total -bios.total.mean()
In [74]:
anomalia
Out[74]:
0    -0.142369
1    -0.142364
2    -0.072538
3    -0.077554
4    -0.049128
5    -0.031647
6    -0.087743
7    -0.112753
8    -0.112000
9    -0.125583
10   -0.123362
11    0.583039
12    0.427894
13   -0.113969
14   -0.068042
15    0.617369
16    0.596116
17   -0.065302
18   -0.138729
19   -0.142369
20   -0.139074
21   -0.097213
22   -0.121107
23    0.036837
24   -0.124998
25   -0.096354
26   -0.077057
Name: total, dtype: float64
In [75]:
test_column = anomalia
bios= bios.assign(test_column =test_column)

title = r'Anomalies burned area pixels (#/$\mathrm{km}^{2}$) by biome N-S parts in (2001-2017)'

name = 'total_anomalies_biomes_nsparts'
draw_map(bios,'test_column',title=title,name=name,cmap='seismic',vmin=anomalia.min(),vmax=anomalia.max())
In [94]:
def test_map(df,column,title=None,vmin=0,vmax=1,name='name',dpi=100,cmap='OrRd'):
    fig, ax = plt.subplots(figsize=(12, 8))

    ax.set_aspect('equal')
    ax = df.plot(ax =ax, column=column, cmap=cmap,vmin=vmin, vmax=vmax)
    ax.set_axis_off()
    
    norm = cls.Normalize(vmin, vmax)
    cmmapable = cm.ScalarMappable(norm, cmap)
    
    cmmapable._A = []
    cbaxes = inset_axes(ax, width="80%", height="1%", loc=8)
    cb = plt.colorbar(cmmapable, cax=cbaxes,orientation="horizontal") 

    cb.set_label(title, fontsize=20, family='Times New Roman')
    cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=15, family='Times New Roman')
    fig.tight_layout()
    plt.show()
    fig.savefig(name, dpi=dpi, bbox_inches='tight')
In [95]:
test_map(bios,'test_column',title='teste',name='teste_tight',cmap='seismic',vmin=vmin,vmax=vmax,dpi=600)
C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\matplotlib\figure.py:2267: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "

Análise sem mapas

In [6]:
bios.columns
Out[6]:
Index(['OBJECTID', 'BIOME_NUM', 'is_north', 'SUM_2001_J', 'SUM_2001_F',
       'SUM_2001_M', 'SUM_2001_A', 'SUM_2001_1', 'SUM_2001_2', 'SUM_2001_3',
       ...
       'SUM_2017_3', 'SUM_2017_4', 'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N',
       'SUM_2017_D', 'SUM_Area', 'Shape_Leng', 'Shape_Area', 'geometry'],
      dtype='object', length=211)
In [7]:
len(bios.columns)
Out[7]:
211
In [10]:
relevant_columns = bios.columns[1:-3]
In [11]:
relevant_columns
Out[11]:
Index(['BIOME_NUM', 'is_north', 'SUM_2001_J', 'SUM_2001_F', 'SUM_2001_M',
       'SUM_2001_A', 'SUM_2001_1', 'SUM_2001_2', 'SUM_2001_3', 'SUM_2001_4',
       ...
       'SUM_2017_A', 'SUM_2017_1', 'SUM_2017_2', 'SUM_2017_3', 'SUM_2017_4',
       'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N', 'SUM_2017_D', 'SUM_Area'],
      dtype='object', length=207)
In [12]:
bios = bios [relevant_columns]
In [13]:
type( bios)
Out[13]:
pandas.core.frame.DataFrame
In [64]:
bios
Out[64]:
BIOME_NUM biome_names is_north SUM_2001_J SUM_2001_F SUM_2001_M SUM_2001_A SUM_2001_1 SUM_2001_2 SUM_2001_3 ... intra_02 intra_03 intra_04 intra_05 intra_06 intra_07 intra_08 intra_09 intra_10 intra_11
0 0.0 NaN n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 NaN y 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000003 0.000000 5.462977e-07 0.000004 0.000002 0.000001 0.000002 0.000000 0.000003 0.000017
2 1.0 Tropical & Subtropical Moist Broadleaf Forests n 853.0 2652.0 1633.0 2502.0 13843.0 75410.0 43368.0 ... 0.012454 0.009650 3.438312e-02 0.068215 0.120540 0.251199 0.340363 0.203065 0.089189 0.031144
3 1.0 Tropical & Subtropical Moist Broadleaf Forests y 50725.0 99315.0 71889.0 36077.0 2371.0 132.0 1282.0 ... 0.353175 0.156375 3.652776e-02 0.004897 0.012228 0.013311 0.004517 0.009714 0.039202 0.109673
4 2.0 Tropical & Subtropical Dry Broadleaf Forests n 615.0 85.0 185.0 1817.0 10985.0 14417.0 5920.0 ... 0.008590 0.018845 7.699744e-02 0.082440 0.104370 0.320773 0.473293 0.298295 0.149724 0.035194
5 2.0 Tropical & Subtropical Dry Broadleaf Forests y 95658.0 43119.0 18711.0 15324.0 8250.0 1080.0 1940.0 ... 0.283610 0.202284 1.002158e-01 0.017579 0.023285 0.011645 0.006475 0.005191 0.027944 0.112090
6 3.0 Tropical & Subtropical Coniferous Forests y 148.0 526.0 2791.0 8287.0 11764.0 269.0 1.0 ... 0.108315 0.272320 3.855076e-01 0.122471 0.004491 0.001409 0.000508 0.000343 0.001292 0.002237
7 4.0 Temperate Broadleaf & Mixed Forests n 571.0 421.0 361.0 280.0 93.0 133.0 365.0 ... 0.034749 0.058866 2.560340e-02 0.004537 0.003669 0.017960 0.035439 0.059759 0.041252 0.071087
8 4.0 Temperate Broadleaf & Mixed Forests y 413.0 654.0 6805.0 30889.0 2101.0 10200.0 35909.0 ... 0.055390 0.098682 5.660307e-02 0.074433 0.028823 0.061374 0.062093 0.047467 0.016587 0.002704
9 5.0 Temperate Conifer Forests y 105.0 93.0 757.0 3078.0 970.0 1375.0 1952.0 ... 0.028269 0.037746 3.536175e-02 0.026644 0.038284 0.067254 0.032757 0.008639 0.003408 0.001416
10 6.0 Boreal Forests/Taiga y 137.0 0.0 9.0 6406.0 5515.0 11559.0 80971.0 ... 0.023204 0.027828 3.118692e-02 0.052316 0.113025 0.057409 0.015415 0.002529 0.000122 0.000012
11 7.0 Tropical & Subtropical Grasslands, Savannas & ... n 27101.0 9849.0 22677.0 149439.0 624424.0 1292553.0 944045.0 ... 0.079530 0.211124 8.409978e-01 1.530914 2.099607 2.740843 2.677223 1.326844 0.533790 0.168504
12 7.0 Tropical & Subtropical Grasslands, Savannas & ... y 1432134.0 554325.0 237121.0 88967.0 23052.0 2546.0 694.0 ... 0.394356 0.159908 6.175877e-02 0.016315 0.008183 0.006923 0.036553 0.624183 1.782666 3.219726
13 8.0 Temperate Grasslands, Savannas & Shrublands n 161543.0 23307.0 13567.0 1180.0 1190.0 629.0 1022.0 ... 0.035511 0.022063 1.173728e-02 0.007306 0.012654 0.027312 0.026244 0.021315 0.031295 0.068935
14 8.0 Temperate Grasslands, Savannas & Shrublands y 2814.0 1472.0 4996.0 49566.0 9589.0 47708.0 191841.0 ... 0.067775 0.173409 9.762831e-02 0.116792 0.200371 0.260621 0.202629 0.115774 0.010980 0.002213
15 9.0 Flooded Grasslands & Savannas n 1770.0 414.0 225.0 1765.0 3495.0 48161.0 89421.0 ... 0.108279 0.173424 4.562323e-01 2.240476 3.118739 3.174424 2.017859 0.934135 0.361001 0.125575
16 9.0 Flooded Grasslands & Savannas y 137417.0 53453.0 33581.0 28751.0 6898.0 2217.0 811.0 ... 1.228887 0.960041 3.217809e-01 0.104156 0.046093 0.021205 0.118388 0.526023 1.165145 3.053797
17 10.0 Montane Grasslands & Shrublands n 748.0 294.0 359.0 152.0 3157.0 24521.0 13069.0 ... 0.006195 0.011054 1.023152e-01 0.182353 0.214408 0.316580 0.253018 0.135183 0.038656 0.013161
18 10.0 Montane Grasslands & Shrublands y 3344.0 3530.0 1117.0 181.0 33.0 250.0 47.0 ... 0.006600 0.001719 8.670712e-04 0.001569 0.002739 0.004038 0.003458 0.002911 0.001431 0.007303
19 11.0 Tundra n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
20 11.0 Tundra y 0.0 0.0 0.0 0.0 2.0 577.0 7202.0 ... 0.000106 0.000100 1.020824e-03 0.010369 0.021539 0.020342 0.002452 0.000087 0.000000 0.000000
21 12.0 Mediterranean Forests, Woodlands & Scrub n 28725.0 3791.0 4446.0 6688.0 250.0 111.0 207.0 ... 0.099691 0.136757 4.857504e-02 0.006250 0.002342 0.008722 0.015455 0.038213 0.079529 0.103650
22 12.0 Mediterranean Forests, Woodlands & Scrub y 235.0 22.0 19.0 188.0 624.0 4800.0 6701.0 ... 0.001588 0.001653 8.942787e-03 0.052219 0.071506 0.092719 0.061284 0.047347 0.015219 0.005686
23 13.0 Deserts & Xeric Shrublands n 371658.0 10911.0 14121.0 93938.0 99653.0 75665.0 42418.0 ... 0.040492 0.094291 7.903277e-02 0.056110 0.077782 0.276834 0.596032 0.791696 0.564313 0.231606
24 13.0 Deserts & Xeric Shrublands y 2120.0 5188.0 8271.0 11549.0 6533.0 17422.0 62596.0 ... 0.009660 0.011707 2.125409e-02 0.043354 0.056592 0.051806 0.025227 0.033302 0.030629 0.001922
25 14.0 Mangroves n 21.0 66.0 17.0 0.0 52.0 64.0 13.0 ... 0.013481 0.010310 2.821634e-02 0.075540 0.090978 0.139139 0.162834 0.150447 0.040253 0.040887
26 14.0 Mangroves y 156.0 1646.0 2332.0 1723.0 653.0 2.0 34.0 ... 0.318420 0.245385 1.592525e-01 0.026060 0.011039 0.009079 0.008936 0.011732 0.008846 0.025338

27 rows × 237 columns

In [15]:
from pandas import ExcelWriter
import xlsxwriter
In [16]:
#writer = ExcelWriter('results_newstyle2.xlsx',engine='xlsxwriter')
#df_finall.to_excel(writer,sheet_name='Burned Pixels',engine='xlsxwriter')
#writer.save()
In [21]:
bios['SUM_Area'] = bios['SUM_Area'].apply (lambda x:x/1e6)
In [25]:
bio_names = pd.read_excel('biomas_nomes.xlsx')
In [27]:
bio_names.set_index('BIOME_NUM')
Out[27]:
BIOME_NAME
BIOME_NUM
0.0 NaN
1.0 Tropical & Subtropical Moist Broadleaf Forests
2.0 Tropical & Subtropical Dry Broadleaf Forests
3.0 Tropical & Subtropical Coniferous Forests
4.0 Temperate Broadleaf & Mixed Forests
5.0 Temperate Conifer Forests
6.0 Boreal Forests/Taiga
7.0 Tropical & Subtropical Grasslands, Savannas & ...
8.0 Temperate Grasslands, Savannas & Shrublands
9.0 Flooded Grasslands & Savannas
10.0 Montane Grasslands & Shrublands
11.0 Tundra
12.0 Mediterranean Forests, Woodlands & Scrub
13.0 Deserts & Xeric Shrublands
14.0 Mangroves
In [35]:
type(bio_names.loc[8].values[1])
Out[35]:
str
In [36]:
def bioname(bionum):
    return bio_names.loc[bionum].values[1]
In [37]:
bionames = bios['BIOME_NUM'].apply(lambda x:bioname(x))
In [39]:
bios = bios.assign(biome_names = bionames)
In [41]:
bios.columns
Out[41]:
Index(['BIOME_NUM', 'is_north', 'SUM_2001_J', 'SUM_2001_F', 'SUM_2001_M',
       'SUM_2001_A', 'SUM_2001_1', 'SUM_2001_2', 'SUM_2001_3', 'SUM_2001_4',
       ...
       'SUM_2017_1', 'SUM_2017_2', 'SUM_2017_3', 'SUM_2017_4', 'SUM_2017_S',
       'SUM_2017_O', 'SUM_2017_N', 'SUM_2017_D', 'SUM_Area', 'biome_names'],
      dtype='object', length=208)
In [45]:
new_columns =[ bios.columns[0]] +[ bios.columns[-1]]   + list(bios.columns[1:-1]  )
In [46]:
new_columns
Out[46]:
['BIOME_NUM',
 'biome_names',
 'is_north',
 'SUM_2001_J',
 'SUM_2001_F',
 'SUM_2001_M',
 'SUM_2001_A',
 'SUM_2001_1',
 'SUM_2001_2',
 'SUM_2001_3',
 'SUM_2001_4',
 'SUM_2001_S',
 'SUM_2001_O',
 'SUM_2001_N',
 'SUM_2001_D',
 'SUM_2002_J',
 'SUM_2002_F',
 'SUM_2002_M',
 'SUM_2002_A',
 'SUM_2002_1',
 'SUM_2002_2',
 'SUM_2002_3',
 'SUM_2002_4',
 'SUM_2002_S',
 'SUM_2002_O',
 'SUM_2002_N',
 'SUM_2002_D',
 'SUM_2003_J',
 'SUM_2003_F',
 'SUM_2003_M',
 'SUM_2003_A',
 'SUM_2003_1',
 'SUM_2003_2',
 'SUM_2003_3',
 'SUM_2003_4',
 'SUM_2003_S',
 'SUM_2003_O',
 'SUM_2003_N',
 'SUM_2003_D',
 'SUM_2004_J',
 'SUM_2004_F',
 'SUM_2004_M',
 'SUM_2004_A',
 'SUM_2004_1',
 'SUM_2004_2',
 'SUM_2004_3',
 'SUM_2004_4',
 'SUM_2004_S',
 'SUM_2004_O',
 'SUM_2004_N',
 'SUM_2004_D',
 'SUM_2005_J',
 'SUM_2005_F',
 'SUM_2005_M',
 'SUM_2005_A',
 'SUM_2005_1',
 'SUM_2005_2',
 'SUM_2005_3',
 'SUM_2005_4',
 'SUM_2005_S',
 'SUM_2005_O',
 'SUM_2005_N',
 'SUM_2005_D',
 'SUM_2006_J',
 'SUM_2006_F',
 'SUM_2006_M',
 'SUM_2006_A',
 'SUM_2006_1',
 'SUM_2006_2',
 'SUM_2006_3',
 'SUM_2006_4',
 'SUM_2006_S',
 'SUM_2006_O',
 'SUM_2006_N',
 'SUM_2006_D',
 'SUM_2007_J',
 'SUM_2007_F',
 'SUM_2007_M',
 'SUM_2007_A',
 'SUM_2007_1',
 'SUM_2007_2',
 'SUM_2007_3',
 'SUM_2007_4',
 'SUM_2007_S',
 'SUM_2007_O',
 'SUM_2007_N',
 'SUM_2007_D',
 'SUM_2008_J',
 'SUM_2008_F',
 'SUM_2008_M',
 'SUM_2008_A',
 'SUM_2008_1',
 'SUM_2008_2',
 'SUM_2008_3',
 'SUM_2008_4',
 'SUM_2008_S',
 'SUM_2008_O',
 'SUM_2008_N',
 'SUM_2008_D',
 'SUM_2009_J',
 'SUM_2009_F',
 'SUM_2009_M',
 'SUM_2009_A',
 'SUM_2009_1',
 'SUM_2009_2',
 'SUM_2009_3',
 'SUM_2009_4',
 'SUM_2009_S',
 'SUM_2009_O',
 'SUM_2009_N',
 'SUM_2009_D',
 'SUM_2010_J',
 'SUM_2010_F',
 'SUM_2010_M',
 'SUM_2010_A',
 'SUM_2010_1',
 'SUM_2010_2',
 'SUM_2010_3',
 'SUM_2010_4',
 'SUM_2010_S',
 'SUM_2010_O',
 'SUM_2010_N',
 'SUM_2010_D',
 'SUM_2011_J',
 'SUM_2011_F',
 'SUM_2011_M',
 'SUM_2011_A',
 'SUM_2011_1',
 'SUM_2011_2',
 'SUM_2011_3',
 'SUM_2011_4',
 'SUM_2011_S',
 'SUM_2011_O',
 'SUM_2011_N',
 'SUM_2011_D',
 'SUM_2012_J',
 'SUM_2012_F',
 'SUM_2012_M',
 'SUM_2012_A',
 'SUM_2012_1',
 'SUM_2012_2',
 'SUM_2012_3',
 'SUM_2012_4',
 'SUM_2012_S',
 'SUM_2012_O',
 'SUM_2012_N',
 'SUM_2012_D',
 'SUM_2013_J',
 'SUM_2013_F',
 'SUM_2013_M',
 'SUM_2013_A',
 'SUM_2013_1',
 'SUM_2013_2',
 'SUM_2013_3',
 'SUM_2013_4',
 'SUM_2013_S',
 'SUM_2013_O',
 'SUM_2013_N',
 'SUM_2013_D',
 'SUM_2014_J',
 'SUM_2014_F',
 'SUM_2014_M',
 'SUM_2014_A',
 'SUM_2014_1',
 'SUM_2014_2',
 'SUM_2014_3',
 'SUM_2014_4',
 'SUM_2014_S',
 'SUM_2014_O',
 'SUM_2014_N',
 'SUM_2014_D',
 'SUM_2015_J',
 'SUM_2015_F',
 'SUM_2015_M',
 'SUM_2015_A',
 'SUM_2015_1',
 'SUM_2015_2',
 'SUM_2015_3',
 'SUM_2015_4',
 'SUM_2015_S',
 'SUM_2015_O',
 'SUM_2015_N',
 'SUM_2015_D',
 'SUM_2016_J',
 'SUM_2016_F',
 'SUM_2016_M',
 'SUM_2016_A',
 'SUM_2016_1',
 'SUM_2016_2',
 'SUM_2016_3',
 'SUM_2016_4',
 'SUM_2016_S',
 'SUM_2016_O',
 'SUM_2016_N',
 'SUM_2016_D',
 'SUM_2017_J',
 'SUM_2017_F',
 'SUM_2017_M',
 'SUM_2017_A',
 'SUM_2017_1',
 'SUM_2017_2',
 'SUM_2017_3',
 'SUM_2017_4',
 'SUM_2017_S',
 'SUM_2017_O',
 'SUM_2017_N',
 'SUM_2017_D',
 'SUM_Area']
In [47]:
bios = bios[new_columns]
In [51]:
data_columns = bios.columns[3:-1]
In [52]:
data_columns
Out[52]:
Index(['SUM_2001_J', 'SUM_2001_F', 'SUM_2001_M', 'SUM_2001_A', 'SUM_2001_1',
       'SUM_2001_2', 'SUM_2001_3', 'SUM_2001_4', 'SUM_2001_S', 'SUM_2001_O',
       ...
       'SUM_2017_M', 'SUM_2017_A', 'SUM_2017_1', 'SUM_2017_2', 'SUM_2017_3',
       'SUM_2017_4', 'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N', 'SUM_2017_D'],
      dtype='object', length=204)
In [49]:
writer = ExcelWriter('biome_analysis.xlsx',engine='xlsxwriter')
bios.to_excel(writer,sheet_name='original',engine='xlsxwriter', index= False)
In [53]:
inter_cols = {}
for yr in range(17):
    inter_cols[yr] = data_columns[12*yr:12*yr +12]
In [ ]:
intra_cols = {}
for mo in range(12):
    intra_cols[mo] = [data_columns[mo + yr *12  ] for yr in range(17)]
In [58]:
area = bios['SUM_Area']
In [59]:
for yr in range(17):
    inter = bios[  inter_cols[yr]].sum(axis=1)/area
    label = 'inter_' + str(yr +2001)
    bios= bios.assign(label=inter)
    bios = bios.rename(columns={'label': label})
In [61]:
inter_columns = bios.columns[-17:]
In [67]:
inter_columns
Out[67]:
Index(['inter_2001', 'inter_2002', 'inter_2003', 'inter_2004', 'inter_2005',
       'inter_2006', 'inter_2007', 'inter_2008', 'inter_2009', 'inter_2010',
       'inter_2011', 'inter_2012', 'inter_2013', 'inter_2014', 'inter_2015',
       'inter_2016', 'inter_2017'],
      dtype='object')
In [63]:
for mo in range(12):
    intra = bios[ intra_cols[mo]].sum(axis=1)/area
    label = 'intra_{:02}'.format(mo)
    bios = bios.assign(label=intra)
    bios = bios.rename(columns={'label': label})
In [65]:
intra_columns = bios.columns[-12:]
In [66]:
intra_columns
Out[66]:
Index(['intra_00', 'intra_01', 'intra_02', 'intra_03', 'intra_04', 'intra_05',
       'intra_06', 'intra_07', 'intra_08', 'intra_09', 'intra_10', 'intra_11'],
      dtype='object')
In [57]:
intra_cols
Out[57]:
{0: ['SUM_2001_J',
  'SUM_2002_J',
  'SUM_2003_J',
  'SUM_2004_J',
  'SUM_2005_J',
  'SUM_2006_J',
  'SUM_2007_J',
  'SUM_2008_J',
  'SUM_2009_J',
  'SUM_2010_J',
  'SUM_2011_J',
  'SUM_2012_J',
  'SUM_2013_J',
  'SUM_2014_J',
  'SUM_2015_J',
  'SUM_2016_J',
  'SUM_2017_J'],
 1: ['SUM_2001_F',
  'SUM_2002_F',
  'SUM_2003_F',
  'SUM_2004_F',
  'SUM_2005_F',
  'SUM_2006_F',
  'SUM_2007_F',
  'SUM_2008_F',
  'SUM_2009_F',
  'SUM_2010_F',
  'SUM_2011_F',
  'SUM_2012_F',
  'SUM_2013_F',
  'SUM_2014_F',
  'SUM_2015_F',
  'SUM_2016_F',
  'SUM_2017_F'],
 2: ['SUM_2001_M',
  'SUM_2002_M',
  'SUM_2003_M',
  'SUM_2004_M',
  'SUM_2005_M',
  'SUM_2006_M',
  'SUM_2007_M',
  'SUM_2008_M',
  'SUM_2009_M',
  'SUM_2010_M',
  'SUM_2011_M',
  'SUM_2012_M',
  'SUM_2013_M',
  'SUM_2014_M',
  'SUM_2015_M',
  'SUM_2016_M',
  'SUM_2017_M'],
 3: ['SUM_2001_A',
  'SUM_2002_A',
  'SUM_2003_A',
  'SUM_2004_A',
  'SUM_2005_A',
  'SUM_2006_A',
  'SUM_2007_A',
  'SUM_2008_A',
  'SUM_2009_A',
  'SUM_2010_A',
  'SUM_2011_A',
  'SUM_2012_A',
  'SUM_2013_A',
  'SUM_2014_A',
  'SUM_2015_A',
  'SUM_2016_A',
  'SUM_2017_A'],
 4: ['SUM_2001_1',
  'SUM_2002_1',
  'SUM_2003_1',
  'SUM_2004_1',
  'SUM_2005_1',
  'SUM_2006_1',
  'SUM_2007_1',
  'SUM_2008_1',
  'SUM_2009_1',
  'SUM_2010_1',
  'SUM_2011_1',
  'SUM_2012_1',
  'SUM_2013_1',
  'SUM_2014_1',
  'SUM_2015_1',
  'SUM_2016_1',
  'SUM_2017_1'],
 5: ['SUM_2001_2',
  'SUM_2002_2',
  'SUM_2003_2',
  'SUM_2004_2',
  'SUM_2005_2',
  'SUM_2006_2',
  'SUM_2007_2',
  'SUM_2008_2',
  'SUM_2009_2',
  'SUM_2010_2',
  'SUM_2011_2',
  'SUM_2012_2',
  'SUM_2013_2',
  'SUM_2014_2',
  'SUM_2015_2',
  'SUM_2016_2',
  'SUM_2017_2'],
 6: ['SUM_2001_3',
  'SUM_2002_3',
  'SUM_2003_3',
  'SUM_2004_3',
  'SUM_2005_3',
  'SUM_2006_3',
  'SUM_2007_3',
  'SUM_2008_3',
  'SUM_2009_3',
  'SUM_2010_3',
  'SUM_2011_3',
  'SUM_2012_3',
  'SUM_2013_3',
  'SUM_2014_3',
  'SUM_2015_3',
  'SUM_2016_3',
  'SUM_2017_3'],
 7: ['SUM_2001_4',
  'SUM_2002_4',
  'SUM_2003_4',
  'SUM_2004_4',
  'SUM_2005_4',
  'SUM_2006_4',
  'SUM_2007_4',
  'SUM_2008_4',
  'SUM_2009_4',
  'SUM_2010_4',
  'SUM_2011_4',
  'SUM_2012_4',
  'SUM_2013_4',
  'SUM_2014_4',
  'SUM_2015_4',
  'SUM_2016_4',
  'SUM_2017_4'],
 8: ['SUM_2001_S',
  'SUM_2002_S',
  'SUM_2003_S',
  'SUM_2004_S',
  'SUM_2005_S',
  'SUM_2006_S',
  'SUM_2007_S',
  'SUM_2008_S',
  'SUM_2009_S',
  'SUM_2010_S',
  'SUM_2011_S',
  'SUM_2012_S',
  'SUM_2013_S',
  'SUM_2014_S',
  'SUM_2015_S',
  'SUM_2016_S',
  'SUM_2017_S'],
 9: ['SUM_2001_O',
  'SUM_2002_O',
  'SUM_2003_O',
  'SUM_2004_O',
  'SUM_2005_O',
  'SUM_2006_O',
  'SUM_2007_O',
  'SUM_2008_O',
  'SUM_2009_O',
  'SUM_2010_O',
  'SUM_2011_O',
  'SUM_2012_O',
  'SUM_2013_O',
  'SUM_2014_O',
  'SUM_2015_O',
  'SUM_2016_O',
  'SUM_2017_O'],
 10: ['SUM_2001_N',
  'SUM_2002_N',
  'SUM_2003_N',
  'SUM_2004_N',
  'SUM_2005_N',
  'SUM_2006_N',
  'SUM_2007_N',
  'SUM_2008_N',
  'SUM_2009_N',
  'SUM_2010_N',
  'SUM_2011_N',
  'SUM_2012_N',
  'SUM_2013_N',
  'SUM_2014_N',
  'SUM_2015_N',
  'SUM_2016_N',
  'SUM_2017_N'],
 11: ['SUM_2001_D',
  'SUM_2002_D',
  'SUM_2003_D',
  'SUM_2004_D',
  'SUM_2005_D',
  'SUM_2006_D',
  'SUM_2007_D',
  'SUM_2008_D',
  'SUM_2009_D',
  'SUM_2010_D',
  'SUM_2011_D',
  'SUM_2012_D',
  'SUM_2013_D',
  'SUM_2014_D',
  'SUM_2015_D',
  'SUM_2016_D',
  'SUM_2017_D']}
In [71]:
total = bios[data_columns].sum(axis=1)
In [73]:
total_area = bios[data_columns].sum(axis=1)/area
In [75]:
colunas_hemis =  list(bios.columns[:3]) + ['SUM_Area'] 
In [76]:
colunas_hemis
Out[76]:
['BIOME_NUM', 'biome_names', 'is_north', 'SUM_Area']
In [77]:
table_hemis = bios[colunas_hemis]
In [79]:
table_hemis = table_hemis.assign(total = total)
In [80]:
table_hemis = table_hemis.assign(total_area = total_area)
In [82]:
table_hemis['biome_names'][11]
Out[82]:
'Tropical & Subtropical Grasslands, Savannas & Shrublands'
In [83]:
table_hemis.to_excel(writer,sheet_name='totais',engine='xlsxwriter', index= False)
In [84]:
writer.save()
In [85]:
table_hemis
Out[85]:
BIOME_NUM biome_names is_north SUM_Area total total_area
0 0.0 NaN n 1.223785e+07 0.0 0.000000
1 0.0 NaN y 1.830504e+06 160.0 0.000087
2 1.0 Tropical & Subtropical Moist Broadleaf Forests n 9.798644e+06 11632193.0 1.187123
3 1.0 Tropical & Subtropical Moist Broadleaf Forests y 9.658434e+06 10642237.0 1.101859
4 2.0 Tropical & Subtropical Dry Broadleaf Forests n 1.629210e+06 2582446.0 1.585091
5 2.0 Tropical & Subtropical Dry Broadleaf Forests y 2.228990e+06 4195577.0 1.882277
6 3.0 Tropical & Subtropical Coniferous Forests y 6.813304e+05 632711.0 0.928641
7 4.0 Temperate Broadleaf & Mixed Forests n 1.107861e+06 557773.0 0.503469
8 4.0 Temperate Broadleaf & Mixed Forests y 1.139073e+07 5880822.0 0.516282
9 5.0 Temperate Conifer Forests y 3.744809e+06 1068629.0 0.285363
10 6.0 Boreal Forests/Taiga y 1.529911e+07 4943428.0 0.323119
11 7.0 Tropical & Subtropical Grasslands, Savannas & ... n 1.166143e+07 143808137.0 12.331943
12 7.0 Tropical & Subtropical Grasslands, Savannas & ... y 9.758549e+06 94604022.0 9.694477
13 8.0 Temperate Grasslands, Savannas & Shrublands n 2.208689e+06 1066350.0 0.482798
14 8.0 Temperate Grasslands, Savannas & Shrublands y 8.369744e+06 10575623.0 1.263554
15 9.0 Flooded Grasslands & Savannas n 4.905659e+05 6335929.0 12.915551
16 9.0 Flooded Grasslands & Savannas y 6.645111e+05 8342438.0 12.554249
17 10.0 Montane Grasslands & Shrublands n 1.216818e+06 1594208.0 1.310145
18 10.0 Montane Grasslands & Shrublands y 3.666365e+06 226849.0 0.061873
19 11.0 Tundra n 7.603930e+04 0.0 0.000000
20 11.0 Tundra y 8.303100e+06 465112.0 0.056017
21 12.0 Mediterranean Forests, Woodlands & Scrub n 1.112711e+06 854169.0 0.767646
22 12.0 Mediterranean Forests, Woodlands & Scrub y 2.153356e+06 778352.0 0.361460
23 13.0 Deserts & Xeric Shrublands n 5.358246e+06 16323949.0 3.046510
24 13.0 Deserts & Xeric Shrublands y 2.097879e+07 6195229.0 0.295309
25 14.0 Mangroves n 7.410599e+04 57970.0 0.782258
26 14.0 Mangroves y 2.107094e+05 233953.0 1.110311
In [86]:
table_hemis.columns
Out[86]:
Index(['BIOME_NUM', 'biome_names', 'is_north', 'SUM_Area', 'total',
       'total_area'],
      dtype='object')
In [92]:
dict_agg = {'is_north': 'first', 'biome_names': 'first', 'SUM_Area': 'sum', 'total':'sum'}
In [96]:
table_hemis = table_hemis[['BIOME_NUM', 'biome_names', 'is_north', 'SUM_Area', 'total']].groupby('BIOME_NUM').agg(dict_agg).drop('is_north', axis=1)
In [98]:
total_area=  table_hemis['total']/ table_hemis['SUM_Area']
In [99]:
table_hemis = table_hemis.assign(total_area = total_area)
In [108]:
table_hemis
Out[108]:
biome_names SUM_Area total total_area
BIOME_NUM
0.0 NaN 1.406836e+07 160.0 0.000011
1.0 Tropical & Subtropical Moist Broadleaf Forests 1.945708e+07 22274430.0 1.144798
2.0 Tropical & Subtropical Dry Broadleaf Forests 3.858201e+06 6778023.0 1.756783
3.0 Tropical & Subtropical Coniferous Forests 6.813304e+05 632711.0 0.928641
4.0 Temperate Broadleaf & Mixed Forests 1.249859e+07 6438595.0 0.515146
5.0 Temperate Conifer Forests 3.744809e+06 1068629.0 0.285363
6.0 Boreal Forests/Taiga 1.529911e+07 4943428.0 0.323119
7.0 Tropical & Subtropical Grasslands, Savannas & ... 2.141998e+07 238412159.0 11.130362
8.0 Temperate Grasslands, Savannas & Shrublands 1.057843e+07 11641973.0 1.100539
9.0 Flooded Grasslands & Savannas 1.155077e+06 14678367.0 12.707695
10.0 Montane Grasslands & Shrublands 4.883184e+06 1821057.0 0.372924
11.0 Tundra 8.379140e+06 465112.0 0.055508
12.0 Mediterranean Forests, Woodlands & Scrub 3.266067e+06 1632521.0 0.499843
13.0 Deserts & Xeric Shrublands 2.633703e+07 22519178.0 0.855038
14.0 Mangroves 2.848154e+05 291923.0 1.024955
In [109]:
writer = ExcelWriter('biome_analysis2.xlsx',engine='xlsxwriter')
table_hemis.to_excel(writer,sheet_name='totais2',engine='xlsxwriter')
In [110]:
writer.save()
In [112]:
from openpyxl import load_workbook
In [135]:
wb = load_workbook('biome_analysis.xlsx')
In [136]:
writer = pd.ExcelWriter('biome_analysis.xlsx',engine='openpyxl') 
In [137]:
writer.book = wb
In [138]:
writer.sheets = dict((ws.title, ws) for ws in wb.worksheets)
In [139]:
table_hemis.to_excel(writer, sheet_name='total_2')
In [140]:
writer.save()
In [142]:
#código acima, supostamente abria ficheiro excel já existente, e acrescentava uma nova folha. na verdade, acrescenteu uma
#nova folha mas não ao ficheiro já existente
In [143]:
bios
Out[143]:
BIOME_NUM biome_names is_north SUM_2001_J SUM_2001_F SUM_2001_M SUM_2001_A SUM_2001_1 SUM_2001_2 SUM_2001_3 ... intra_02 intra_03 intra_04 intra_05 intra_06 intra_07 intra_08 intra_09 intra_10 intra_11
0 0.0 NaN n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 NaN y 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000003 0.000000 5.462977e-07 0.000004 0.000002 0.000001 0.000002 0.000000 0.000003 0.000017
2 1.0 Tropical & Subtropical Moist Broadleaf Forests n 853.0 2652.0 1633.0 2502.0 13843.0 75410.0 43368.0 ... 0.012454 0.009650 3.438312e-02 0.068215 0.120540 0.251199 0.340363 0.203065 0.089189 0.031144
3 1.0 Tropical & Subtropical Moist Broadleaf Forests y 50725.0 99315.0 71889.0 36077.0 2371.0 132.0 1282.0 ... 0.353175 0.156375 3.652776e-02 0.004897 0.012228 0.013311 0.004517 0.009714 0.039202 0.109673
4 2.0 Tropical & Subtropical Dry Broadleaf Forests n 615.0 85.0 185.0 1817.0 10985.0 14417.0 5920.0 ... 0.008590 0.018845 7.699744e-02 0.082440 0.104370 0.320773 0.473293 0.298295 0.149724 0.035194
5 2.0 Tropical & Subtropical Dry Broadleaf Forests y 95658.0 43119.0 18711.0 15324.0 8250.0 1080.0 1940.0 ... 0.283610 0.202284 1.002158e-01 0.017579 0.023285 0.011645 0.006475 0.005191 0.027944 0.112090
6 3.0 Tropical & Subtropical Coniferous Forests y 148.0 526.0 2791.0 8287.0 11764.0 269.0 1.0 ... 0.108315 0.272320 3.855076e-01 0.122471 0.004491 0.001409 0.000508 0.000343 0.001292 0.002237
7 4.0 Temperate Broadleaf & Mixed Forests n 571.0 421.0 361.0 280.0 93.0 133.0 365.0 ... 0.034749 0.058866 2.560340e-02 0.004537 0.003669 0.017960 0.035439 0.059759 0.041252 0.071087
8 4.0 Temperate Broadleaf & Mixed Forests y 413.0 654.0 6805.0 30889.0 2101.0 10200.0 35909.0 ... 0.055390 0.098682 5.660307e-02 0.074433 0.028823 0.061374 0.062093 0.047467 0.016587 0.002704
9 5.0 Temperate Conifer Forests y 105.0 93.0 757.0 3078.0 970.0 1375.0 1952.0 ... 0.028269 0.037746 3.536175e-02 0.026644 0.038284 0.067254 0.032757 0.008639 0.003408 0.001416
10 6.0 Boreal Forests/Taiga y 137.0 0.0 9.0 6406.0 5515.0 11559.0 80971.0 ... 0.023204 0.027828 3.118692e-02 0.052316 0.113025 0.057409 0.015415 0.002529 0.000122 0.000012
11 7.0 Tropical & Subtropical Grasslands, Savannas & ... n 27101.0 9849.0 22677.0 149439.0 624424.0 1292553.0 944045.0 ... 0.079530 0.211124 8.409978e-01 1.530914 2.099607 2.740843 2.677223 1.326844 0.533790 0.168504
12 7.0 Tropical & Subtropical Grasslands, Savannas & ... y 1432134.0 554325.0 237121.0 88967.0 23052.0 2546.0 694.0 ... 0.394356 0.159908 6.175877e-02 0.016315 0.008183 0.006923 0.036553 0.624183 1.782666 3.219726
13 8.0 Temperate Grasslands, Savannas & Shrublands n 161543.0 23307.0 13567.0 1180.0 1190.0 629.0 1022.0 ... 0.035511 0.022063 1.173728e-02 0.007306 0.012654 0.027312 0.026244 0.021315 0.031295 0.068935
14 8.0 Temperate Grasslands, Savannas & Shrublands y 2814.0 1472.0 4996.0 49566.0 9589.0 47708.0 191841.0 ... 0.067775 0.173409 9.762831e-02 0.116792 0.200371 0.260621 0.202629 0.115774 0.010980 0.002213
15 9.0 Flooded Grasslands & Savannas n 1770.0 414.0 225.0 1765.0 3495.0 48161.0 89421.0 ... 0.108279 0.173424 4.562323e-01 2.240476 3.118739 3.174424 2.017859 0.934135 0.361001 0.125575
16 9.0 Flooded Grasslands & Savannas y 137417.0 53453.0 33581.0 28751.0 6898.0 2217.0 811.0 ... 1.228887 0.960041 3.217809e-01 0.104156 0.046093 0.021205 0.118388 0.526023 1.165145 3.053797
17 10.0 Montane Grasslands & Shrublands n 748.0 294.0 359.0 152.0 3157.0 24521.0 13069.0 ... 0.006195 0.011054 1.023152e-01 0.182353 0.214408 0.316580 0.253018 0.135183 0.038656 0.013161
18 10.0 Montane Grasslands & Shrublands y 3344.0 3530.0 1117.0 181.0 33.0 250.0 47.0 ... 0.006600 0.001719 8.670712e-04 0.001569 0.002739 0.004038 0.003458 0.002911 0.001431 0.007303
19 11.0 Tundra n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.000000 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
20 11.0 Tundra y 0.0 0.0 0.0 0.0 2.0 577.0 7202.0 ... 0.000106 0.000100 1.020824e-03 0.010369 0.021539 0.020342 0.002452 0.000087 0.000000 0.000000
21 12.0 Mediterranean Forests, Woodlands & Scrub n 28725.0 3791.0 4446.0 6688.0 250.0 111.0 207.0 ... 0.099691 0.136757 4.857504e-02 0.006250 0.002342 0.008722 0.015455 0.038213 0.079529 0.103650
22 12.0 Mediterranean Forests, Woodlands & Scrub y 235.0 22.0 19.0 188.0 624.0 4800.0 6701.0 ... 0.001588 0.001653 8.942787e-03 0.052219 0.071506 0.092719 0.061284 0.047347 0.015219 0.005686
23 13.0 Deserts & Xeric Shrublands n 371658.0 10911.0 14121.0 93938.0 99653.0 75665.0 42418.0 ... 0.040492 0.094291 7.903277e-02 0.056110 0.077782 0.276834 0.596032 0.791696 0.564313 0.231606
24 13.0 Deserts & Xeric Shrublands y 2120.0 5188.0 8271.0 11549.0 6533.0 17422.0 62596.0 ... 0.009660 0.011707 2.125409e-02 0.043354 0.056592 0.051806 0.025227 0.033302 0.030629 0.001922
25 14.0 Mangroves n 21.0 66.0 17.0 0.0 52.0 64.0 13.0 ... 0.013481 0.010310 2.821634e-02 0.075540 0.090978 0.139139 0.162834 0.150447 0.040253 0.040887
26 14.0 Mangroves y 156.0 1646.0 2332.0 1723.0 653.0 2.0 34.0 ... 0.318420 0.245385 1.592525e-01 0.026060 0.011039 0.009079 0.008936 0.011732 0.008846 0.025338

27 rows × 237 columns

In [148]:
bios[inter_columns]['inter_2001'].plot(kind='bar')
Out[148]:
<matplotlib.axes._subplots.AxesSubplot at 0x23e030315f8>
In [150]:
bios.columns[:3]
Out[150]:
Index(['BIOME_NUM', 'biome_names', 'is_north'], dtype='object')
In [163]:
labels = ['{} {}'.format( int(bios['BIOME_NUM'].iloc[i]), bios['is_north'].iloc[i].upper()) for i in  bios.index ]
In [164]:
labels
Out[164]:
['0 N',
 '0 Y',
 '1 N',
 '1 Y',
 '2 N',
 '2 Y',
 '3 Y',
 '4 N',
 '4 Y',
 '5 Y',
 '6 Y',
 '7 N',
 '7 Y',
 '8 N',
 '8 Y',
 '9 N',
 '9 Y',
 '10 N',
 '10 Y',
 '11 N',
 '11 Y',
 '12 N',
 '12 Y',
 '13 N',
 '13 Y',
 '14 N',
 '14 Y']
In [175]:
ax = bios[inter_columns].plot(kind='bar') 
ax.set_xticklabels( labels);plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
#fig = plt.gcf()
plt.figure(figsize=(16,24))
plt.show()
<Figure size 1152x1728 with 0 Axes>
In [159]:
ax
Out[159]:
<matplotlib.axes._subplots.AxesSubplot at 0x23e031223c8>
In [160]:
ax.set_xlabel =labels;plt.show()

inter_anual

In [184]:
fig, ax = plt.subplots(figsize=(24,16))
bios[inter_columns].plot(kind='bar',ax= ax) 
ax.set_xticklabels( labels, rotation =None,fontsize=15)
plt.legend(fontsize=15)
plt.show() 
In [ ]:
fig, ax = plt.subplots(figsize=(24,16))
bios[inter_columns].plot(kind='bar',ax= ax) 
ax.set_xticklabels( labels, rotation =None,fontsize=15)
plt.legend(fontsize=15)
plt.show() 
In [211]:
#fig, axes =plt.subplots(3,6,figsize =(24,16))
bios[inter_columns].plot(kind='bar',subplots=True, grid=True,title="Variação interanual", layout=(6, 3), sharex=True, sharey=True, legend = False, )
[ax.set_xticklabels(labels) for ax in plt.gcf().axes]

plt.tight_layout()
plt.show()
In [241]:
'''
fig, axes =plt.subplots(6,3,figsize =(24,16))
bios[inter_columns].plot(axes =axes ,kind='bar',title="Variação interanual",  legend = False, )
[ax.set_xticklabels(labels) for ax in plt.gcf().axes]

plt.tight_layout()
plt.show()
'''
Out[241]:
'\nfig, axes =plt.subplots(6,3,figsize =(24,16))\nbios[inter_columns].plot(axes =axes ,kind=\'bar\',title="Variação interanual",  legend = False, )\n[ax.set_xticklabels(labels) for ax in plt.gcf().axes]\n\nplt.tight_layout()\nplt.show()\n'
In [240]:
'''

fig, axes = plt.subplots(nrows=6, ncols=3)
for i, c in enumerate(bios[inter_columns].columns):
    bios[inter_columns][c].plot(kind='bar', ax=axes[i])
plt.tight_layout()
plt.show()
'''
Out[240]:
"\n\nfig, axes = plt.subplots(nrows=6, ncols=3)\nfor i, c in enumerate(bios[inter_columns].columns):\n    bios[inter_columns][c].plot(kind='bar', ax=axes[i])\nplt.tight_layout()\nplt.show()\n"
In [256]:
for i, c in enumerate(bios[inter_columns].columns):
    bios[inter_columns][c].plot(kind='bar', title = c[-4:])
    plt.gca().set_xticklabels( labels)
    plt.show()
In [223]:
# não fucinona por causa das areas
#bios[list(inter_columns) + ['BIOME_NUM']].groupby('BIOME_NUM').sum()

Intra-anual

In [224]:
fig, ax = plt.subplots(figsize=(24,16))
bios[intra_columns].plot(kind='bar',ax= ax) 
ax.set_xticklabels( labels, rotation =None,fontsize=15)
plt.legend(fontsize=15)
plt.show() 
In [ ]:
month_names
In [230]:
for i, c in enumerate(bios[intra_columns].columns):
    bios[intra_columns][c].plot(kind='bar', title = calendar.month_name[int(c[-2:]) +1][:3])
    plt.gca().set_xticklabels( labels)
    plt.show()
In [229]:
calendar.month_name[int('intra_00'[-2:]) +1][:3]
Out[229]:
'Jan'
In [232]:
bios.columns[:-17-12]
Out[232]:
Index(['BIOME_NUM', 'biome_names', 'is_north', 'SUM_2001_J', 'SUM_2001_F',
       'SUM_2001_M', 'SUM_2001_A', 'SUM_2001_1', 'SUM_2001_2', 'SUM_2001_3',
       ...
       'SUM_2017_A', 'SUM_2017_1', 'SUM_2017_2', 'SUM_2017_3', 'SUM_2017_4',
       'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N', 'SUM_2017_D', 'SUM_Area'],
      dtype='object', length=208)
In [233]:
biomes = bios[bios.columns[:-17-12]]
In [238]:
biomes = biomes.groupby('BIOME_NUM').sum()
In [239]:
biomes.columns
Out[239]:
Index(['SUM_2001_J', 'SUM_2001_F', 'SUM_2001_M', 'SUM_2001_A', 'SUM_2001_1',
       'SUM_2001_2', 'SUM_2001_3', 'SUM_2001_4', 'SUM_2001_S', 'SUM_2001_O',
       ...
       'SUM_2017_A', 'SUM_2017_1', 'SUM_2017_2', 'SUM_2017_3', 'SUM_2017_4',
       'SUM_2017_S', 'SUM_2017_O', 'SUM_2017_N', 'SUM_2017_D', 'SUM_Area'],
      dtype='object', length=205)
In [242]:
inter_cols_t = {}
for yr in range(17):
    inter_cols_t[yr] = biomes.columns[12*yr:12*yr +12]
In [244]:
area_t = biomes['SUM_Area']
In [246]:
for yr in range(17):
    inter = biomes[  inter_cols[yr]].sum(axis=1)/area_t
    label = 'inter_' + str(yr +2001)
    biomes= biomes.assign(label=inter)
    biomes = biomes.rename(columns={'label': label})
In [249]:
inter_columns_t = biomes.columns[-17:]
In [250]:
inter_columns_t
Out[250]:
Index(['inter_2001', 'inter_2002', 'inter_2003', 'inter_2004', 'inter_2005',
       'inter_2006', 'inter_2007', 'inter_2008', 'inter_2009', 'inter_2010',
       'inter_2011', 'inter_2012', 'inter_2013', 'inter_2014', 'inter_2015',
       'inter_2016', 'inter_2017'],
      dtype='object')
In [254]:
fig, ax = plt.subplots(figsize=(24,16))
biomes[inter_columns_t].plot(kind='bar',ax= ax) 
ax.set_xticklabels( range(15), rotation =None,fontsize=15)
plt.legend(fontsize=15)
plt.show() 
In [255]:
for i, c in enumerate(biomes[inter_columns_t].columns):
    biomes[inter_columns_t][c].plot(kind='bar', title = c[-4:])
    #plt.gca().set_xticklabels( labels)
    plt.show()
In [263]:
biomes[inter_columns_t].iloc[0].plot(kind='bar', title =table_hemis.iloc[0]['biome_names']);  plt.gca().set_xticklabels( range(2001,2018))
Out[263]:
[Text(0,0,'2001'),
 Text(0,0,'2002'),
 Text(0,0,'2003'),
 Text(0,0,'2004'),
 Text(0,0,'2005'),
 Text(0,0,'2006'),
 Text(0,0,'2007'),
 Text(0,0,'2008'),
 Text(0,0,'2009'),
 Text(0,0,'2010'),
 Text(0,0,'2011'),
 Text(0,0,'2012'),
 Text(0,0,'2013'),
 Text(0,0,'2014'),
 Text(0,0,'2015'),
 Text(0,0,'2016'),
 Text(0,0,'2017')]
In [261]:
table_hemis.iloc[0]['biome_names']
Out[261]:
nan
In [264]:
for i in range(15):
    biomes[inter_columns_t].iloc[i].plot(kind='bar', title =table_hemis.iloc[i]['biome_names'])  
    plt.gca().set_xticklabels( range(2001,2018))
    plt.show()
In [265]:
intra_cols_t = {}
for mo in range(12):
    intra_cols_t[mo] = [biomes.columns[mo + yr *12  ] for yr in range(17)]
In [266]:
intra_cols_t 
Out[266]:
{0: ['SUM_2001_J',
  'SUM_2002_J',
  'SUM_2003_J',
  'SUM_2004_J',
  'SUM_2005_J',
  'SUM_2006_J',
  'SUM_2007_J',
  'SUM_2008_J',
  'SUM_2009_J',
  'SUM_2010_J',
  'SUM_2011_J',
  'SUM_2012_J',
  'SUM_2013_J',
  'SUM_2014_J',
  'SUM_2015_J',
  'SUM_2016_J',
  'SUM_2017_J'],
 1: ['SUM_2001_F',
  'SUM_2002_F',
  'SUM_2003_F',
  'SUM_2004_F',
  'SUM_2005_F',
  'SUM_2006_F',
  'SUM_2007_F',
  'SUM_2008_F',
  'SUM_2009_F',
  'SUM_2010_F',
  'SUM_2011_F',
  'SUM_2012_F',
  'SUM_2013_F',
  'SUM_2014_F',
  'SUM_2015_F',
  'SUM_2016_F',
  'SUM_2017_F'],
 2: ['SUM_2001_M',
  'SUM_2002_M',
  'SUM_2003_M',
  'SUM_2004_M',
  'SUM_2005_M',
  'SUM_2006_M',
  'SUM_2007_M',
  'SUM_2008_M',
  'SUM_2009_M',
  'SUM_2010_M',
  'SUM_2011_M',
  'SUM_2012_M',
  'SUM_2013_M',
  'SUM_2014_M',
  'SUM_2015_M',
  'SUM_2016_M',
  'SUM_2017_M'],
 3: ['SUM_2001_A',
  'SUM_2002_A',
  'SUM_2003_A',
  'SUM_2004_A',
  'SUM_2005_A',
  'SUM_2006_A',
  'SUM_2007_A',
  'SUM_2008_A',
  'SUM_2009_A',
  'SUM_2010_A',
  'SUM_2011_A',
  'SUM_2012_A',
  'SUM_2013_A',
  'SUM_2014_A',
  'SUM_2015_A',
  'SUM_2016_A',
  'SUM_2017_A'],
 4: ['SUM_2001_1',
  'SUM_2002_1',
  'SUM_2003_1',
  'SUM_2004_1',
  'SUM_2005_1',
  'SUM_2006_1',
  'SUM_2007_1',
  'SUM_2008_1',
  'SUM_2009_1',
  'SUM_2010_1',
  'SUM_2011_1',
  'SUM_2012_1',
  'SUM_2013_1',
  'SUM_2014_1',
  'SUM_2015_1',
  'SUM_2016_1',
  'SUM_2017_1'],
 5: ['SUM_2001_2',
  'SUM_2002_2',
  'SUM_2003_2',
  'SUM_2004_2',
  'SUM_2005_2',
  'SUM_2006_2',
  'SUM_2007_2',
  'SUM_2008_2',
  'SUM_2009_2',
  'SUM_2010_2',
  'SUM_2011_2',
  'SUM_2012_2',
  'SUM_2013_2',
  'SUM_2014_2',
  'SUM_2015_2',
  'SUM_2016_2',
  'SUM_2017_2'],
 6: ['SUM_2001_3',
  'SUM_2002_3',
  'SUM_2003_3',
  'SUM_2004_3',
  'SUM_2005_3',
  'SUM_2006_3',
  'SUM_2007_3',
  'SUM_2008_3',
  'SUM_2009_3',
  'SUM_2010_3',
  'SUM_2011_3',
  'SUM_2012_3',
  'SUM_2013_3',
  'SUM_2014_3',
  'SUM_2015_3',
  'SUM_2016_3',
  'SUM_2017_3'],
 7: ['SUM_2001_4',
  'SUM_2002_4',
  'SUM_2003_4',
  'SUM_2004_4',
  'SUM_2005_4',
  'SUM_2006_4',
  'SUM_2007_4',
  'SUM_2008_4',
  'SUM_2009_4',
  'SUM_2010_4',
  'SUM_2011_4',
  'SUM_2012_4',
  'SUM_2013_4',
  'SUM_2014_4',
  'SUM_2015_4',
  'SUM_2016_4',
  'SUM_2017_4'],
 8: ['SUM_2001_S',
  'SUM_2002_S',
  'SUM_2003_S',
  'SUM_2004_S',
  'SUM_2005_S',
  'SUM_2006_S',
  'SUM_2007_S',
  'SUM_2008_S',
  'SUM_2009_S',
  'SUM_2010_S',
  'SUM_2011_S',
  'SUM_2012_S',
  'SUM_2013_S',
  'SUM_2014_S',
  'SUM_2015_S',
  'SUM_2016_S',
  'SUM_2017_S'],
 9: ['SUM_2001_O',
  'SUM_2002_O',
  'SUM_2003_O',
  'SUM_2004_O',
  'SUM_2005_O',
  'SUM_2006_O',
  'SUM_2007_O',
  'SUM_2008_O',
  'SUM_2009_O',
  'SUM_2010_O',
  'SUM_2011_O',
  'SUM_2012_O',
  'SUM_2013_O',
  'SUM_2014_O',
  'SUM_2015_O',
  'SUM_2016_O',
  'SUM_2017_O'],
 10: ['SUM_2001_N',
  'SUM_2002_N',
  'SUM_2003_N',
  'SUM_2004_N',
  'SUM_2005_N',
  'SUM_2006_N',
  'SUM_2007_N',
  'SUM_2008_N',
  'SUM_2009_N',
  'SUM_2010_N',
  'SUM_2011_N',
  'SUM_2012_N',
  'SUM_2013_N',
  'SUM_2014_N',
  'SUM_2015_N',
  'SUM_2016_N',
  'SUM_2017_N'],
 11: ['SUM_2001_D',
  'SUM_2002_D',
  'SUM_2003_D',
  'SUM_2004_D',
  'SUM_2005_D',
  'SUM_2006_D',
  'SUM_2007_D',
  'SUM_2008_D',
  'SUM_2009_D',
  'SUM_2010_D',
  'SUM_2011_D',
  'SUM_2012_D',
  'SUM_2013_D',
  'SUM_2014_D',
  'SUM_2015_D',
  'SUM_2016_D',
  'SUM_2017_D']}
In [ ]:
for mo in range(12):
    intra = bios[ intra_cols[mo]].sum(axis=1)/area
    label = 'intra_{:02}'.format(mo)
    bios = bios.assign(label=intra)
    bios = bios.rename(columns={'label': label})
In [267]:
#calendar.month_name[int(c[-2:]) +1][:3]
In [268]:
months_names = [calendar.month_name[i +1][:3] for i in range(12)]
In [282]:
for i in range(bios.shape[0]):
    title ='{} {}'.format(table_hemis.iloc[int(bios.iloc[i]['BIOME_NUM'])]['biome_names'],bios.iloc[i]['is_north'].upper())
    bios[intra_columns].iloc[i].plot(kind='bar', title=title)  
    plt.gca().set_xticklabels( months_names)
    plt.show()
In [272]:
bios.shape[0]
Out[272]:
27
In [276]:
i= 3
In [277]:
'{} {}'.format(table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]['biome_names'],bios.iloc[i]['is_north'].upper())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-277-af8ef2986b85> in <module>()
----> 1 '{} {}'.format(table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]['biome_names'],bios.iloc[i]['is_north'].upper())

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   1371 
   1372             maybe_callable = com._apply_if_callable(key, self.obj)
-> 1373             return self._getitem_axis(maybe_callable, axis=axis)
   1374 
   1375     def _is_scalar_access(self, key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
   1821         # a single integer
   1822         else:
-> 1823             key = self._convert_scalar_indexer(key, axis)
   1824 
   1825             if not is_integer(key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _convert_scalar_indexer(self, key, axis)
    254         ax = self.obj._get_axis(min(axis, self.ndim - 1))
    255         # a scalar
--> 256         return ax._convert_scalar_indexer(key, kind=self.name)
    257 
    258     def _convert_slice_indexer(self, key, axis):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\numeric.py in _convert_scalar_indexer(self, key, kind)
    311 
    312         if kind == 'iloc':
--> 313             return self._validate_indexer('positional', key, kind)
    314 
    315         return key

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _validate_indexer(self, form, key, kind)
   3493             pass
   3494         elif kind in ['iloc', 'getitem']:
-> 3495             self._invalid_indexer(form, key)
   3496         return key
   3497 

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _invalid_indexer(self, form, key)
   1574                         "indexers [{key}] of {kind}".format(
   1575                             form=form, klass=type(self), key=key,
-> 1576                             kind=type(key)))
   1577 
   1578     def get_duplicates(self):

TypeError: cannot do positional indexing on <class 'pandas.core.indexes.numeric.Float64Index'> with these indexers [1.0] of <class 'numpy.float64'>
In [278]:
table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]['biome_names']
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-278-078ea2eab510> in <module>()
----> 1 table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]['biome_names']

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   1371 
   1372             maybe_callable = com._apply_if_callable(key, self.obj)
-> 1373             return self._getitem_axis(maybe_callable, axis=axis)
   1374 
   1375     def _is_scalar_access(self, key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
   1821         # a single integer
   1822         else:
-> 1823             key = self._convert_scalar_indexer(key, axis)
   1824 
   1825             if not is_integer(key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _convert_scalar_indexer(self, key, axis)
    254         ax = self.obj._get_axis(min(axis, self.ndim - 1))
    255         # a scalar
--> 256         return ax._convert_scalar_indexer(key, kind=self.name)
    257 
    258     def _convert_slice_indexer(self, key, axis):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\numeric.py in _convert_scalar_indexer(self, key, kind)
    311 
    312         if kind == 'iloc':
--> 313             return self._validate_indexer('positional', key, kind)
    314 
    315         return key

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _validate_indexer(self, form, key, kind)
   3493             pass
   3494         elif kind in ['iloc', 'getitem']:
-> 3495             self._invalid_indexer(form, key)
   3496         return key
   3497 

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _invalid_indexer(self, form, key)
   1574                         "indexers [{key}] of {kind}".format(
   1575                             form=form, klass=type(self), key=key,
-> 1576                             kind=type(key)))
   1577 
   1578     def get_duplicates(self):

TypeError: cannot do positional indexing on <class 'pandas.core.indexes.numeric.Float64Index'> with these indexers [1.0] of <class 'numpy.float64'>
In [280]:
table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-280-556c80f09204> in <module>()
----> 1 table_hemis.iloc[bios.iloc[i]['BIOME_NUM']]

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   1371 
   1372             maybe_callable = com._apply_if_callable(key, self.obj)
-> 1373             return self._getitem_axis(maybe_callable, axis=axis)
   1374 
   1375     def _is_scalar_access(self, key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
   1821         # a single integer
   1822         else:
-> 1823             key = self._convert_scalar_indexer(key, axis)
   1824 
   1825             if not is_integer(key):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexing.py in _convert_scalar_indexer(self, key, axis)
    254         ax = self.obj._get_axis(min(axis, self.ndim - 1))
    255         # a scalar
--> 256         return ax._convert_scalar_indexer(key, kind=self.name)
    257 
    258     def _convert_slice_indexer(self, key, axis):

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\numeric.py in _convert_scalar_indexer(self, key, kind)
    311 
    312         if kind == 'iloc':
--> 313             return self._validate_indexer('positional', key, kind)
    314 
    315         return key

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _validate_indexer(self, form, key, kind)
   3493             pass
   3494         elif kind in ['iloc', 'getitem']:
-> 3495             self._invalid_indexer(form, key)
   3496         return key
   3497 

C:\ProgramData\Anaconda3\envs\geopandas\lib\site-packages\pandas\core\indexes\base.py in _invalid_indexer(self, form, key)
   1574                         "indexers [{key}] of {kind}".format(
   1575                             form=form, klass=type(self), key=key,
-> 1576                             kind=type(key)))
   1577 
   1578     def get_duplicates(self):

TypeError: cannot do positional indexing on <class 'pandas.core.indexes.numeric.Float64Index'> with these indexers [1.0] of <class 'numpy.float64'>